<?php

class DB{

	/*** Declare instance ***/
	private static $instance = NULL;
	/*
	* the constructor is set to private so
	* so nobody can create a new instance using new
	*
	*/
	private function __construct() {
	  /*** maybe set the db name here later ***/
		// Database
			
	}
	
	/**
	*
	* Return DB instance or create intitial connection
	*
	* @return object (PDO)
	*
	* @access public
	*
	*/
	public static function getInstance($db='mysql') {
	
	
		if($db==='mongodb'){
			try {			
				// open connection to MongoDB server			
				$conn = new Mongo();
			
			}
			catch (MongoConnectionException $e) {
  				die('Error connecting to MongoDB server');
			} catch (MongoException $e) {
  				die('Error: ' . $e->getMessage());
			}
			// access database
			return  $conn->kdict;;
		}else{
			if (!self::$instance)
			{
			    self::$instance = new PDO("mysql:dbname=".DB_NAME.";host=".DB_HOST, DB_USER,DB_PASSWORD);;
			    self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			    self::$instance->exec("SET NAMES 'utf8';");
			}
			return self::$instance;
		}
	}
	
	/**
	*
	* Like the constructor, we make __clone private
	* so nobody can clone the instance
	*
	*/
	private function __clone(){
	}
	
	
	
} /*** end of class ***/

?>
